package zsh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import zsh.domain.Book;
import zsh.mapper.BookMapper;
import zsh.service.IBookService;

import java.util.Collections;
import java.util.List;
@Service
@AllArgsConstructor
public class BookService implements IBookService {
    private BookMapper bookMapper;
    @Override
    public int addBook(Book book) {
        return bookMapper.insertBook(book);
    }

    @Override
    public int deleteBook(int id) {
        return bookMapper.deleteBook(id);
    }

    @Override
    public int updateBook(Book book) {
        return bookMapper.updateBook(book);
    }

    @Override
    public Book getBookById(int id) {
        return bookMapper.selectBookById(id);
    }

    @Override
    public List<Book> getAllBooks(Book book) {
        return bookMapper.selectAllBook(book);
    }

    @Override
    public PageInfo<Book> getAllBooksByPage(Book book, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Book> books = bookMapper.selectAllBooks(book);
        return new PageInfo<>(books);
    }
}
